/*
 * @Author: carrieryu
 * @Date: 2023-02-19 22:46:28
 * @LastEditTime: 2023-02-21 21:41:12
 * @LastEditors: carrieryu
 * @Description: 简单实现一个剪刀石头布游戏
 * @FilePath: \github_project\node-practise\first-game\index.js
 * @Company: yu project
 */
const playerAction = process.argv[process.argv.length - 1]
    // node index.js rock
    // console.log(playerAction) // rock

if (playerAction !== "rock" && playerAction !== "scissor" && playerAction !== "paper") {
    console.log("请输入 rock 或 scissor 或 paper")
    return
}

// 玩家赢了：
//    用户   玩家
// 1. 剪刀   布
// 2. 石头   剪刀
// 3. 布     剪刀

// 机器随机生成剪刀石头布
const randomNum = Math.random() * 3
let computerAction = randomNum < 1 ? "rock" : randomNum < 2 ? "scissor" : "paper"
console.log(`玩家出：${playerAction}；电脑出：${computerAction}`)

if (playerAction === computerAction) console.log("平手")
else if (playerAction === "scissor" && computerAction === "paper" || playerAction === "rock" && computerAction === "scissor" || playerAction === "paper" && computerAction === "rock") {
    console.log("你赢了")
} else {
    console.log("你输了")
}
